import $service from '../../../../../service';
const app = getApp()
let isLoading = true
let params = {
  size: 10,
  current: 1,
  orderState: ''
}
Page({
  data: {
    tabList: [{
      name: '全部',
      index: ''
    }, {
      name: '待付款',
      index: '0'
    }, {
      name: '已支付',
      index: '1'
    }, {
      name: '已退款',
      index: '-1'
    },],
    toView: 'v',
    tab: '',
    list: []
  },
  taptab(e) {
    let {index} = e.currentTarget.dataset
    params.size = 10
    isLoading = true
    params.orderState = index
    this.setData({
      tab: index,
      toView: 'v' + index,
      list: []
    })
    this.queryInquiryOrderListPage()
  },
  queryInquiryOrderListPage() {
    app.http.queryInquiryOrderListPage(params).then(res => {
      let {total, list} = res.data
      if (total > this.data.list.length) {
        this.setData({
          list
        })
      } else {
        isLoading = false
        $service.showToast('到底啦！')
      }
    }).catch(err => {
      $service.showToast(err.msg)
    })
  },
  onReachBottom() {
    if (isLoading) {
      params.size = params.size + 10
      this.queryInquiryOrderListPage()
    }
  },
  onLoad() {
    params.size = 10
    params.orderState = ''
    this.queryInquiryOrderListPage()
  }
})